package pl.edu.mimuw.irs.rcp.controller.editor.roles.command;

import pl.edu.mimuw.irs.core.model.design.net.IRSWorkflow;
import pl.edu.mimuw.irs.core.model.design.resource.Requirement;
import pl.edu.mimuw.irs.core.model.design.resource.Role;
import pl.edu.mimuw.irs.core.model.design.resource.RoleInstance;

public class RenameWorkflowRoleCommand extends AbstractWorkflowRoleCommand {

	// *** Attributes

	private String newName;
	private String oldName;
	public String getNewName() {
		return newName;
	}
	public String getOldName() {
		return oldName;
	}
	
	// *** Constructors

	public RenameWorkflowRoleCommand(IRSWorkflow workflow, Role role, String newName) {
		super(workflow, role);
		this.oldName = role.getName();
		this.newName = newName;
	}
	
	// *** Methods

//	@Override
//	public void execute() {
//		super.execute();
//		getRole().setName(getNewName());
//	}
//	
//	@Override
//	public void undo() {
//		super.undo();
//		getRole().setName(getOldName());
//	}
//	
	@Override
	protected void execute(Requirement requirement) {
		RoleInstance roleInstance = requirement.getRolesMap().get(getRole());
		if (roleInstance == null) return;
		
		roleInstance.getRole().setName(getNewName());
		getRole().setName(getNewName());
	}
	
	@Override
	protected void undo(Requirement requirement) {
		RoleInstance roleInstance = requirement.getRolesMap().get(getRole());
		if (roleInstance == null) return;
		
		roleInstance.getRole().setName(getOldName());
		getRole().setName(getOldName());
	}
}
